<template>
    <div>
        <h1>登录页面</h1>
        <p>用户：<input type="text" v-model="username"></p>
        <p>密码：<input type="password" v-model="password"></p>
        <button @click="add">登录</button>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            username:'',
            password:'',
        }
    },
    methods: {
        add(){
            let form_data =new FormData()
            form_data.append('username',this.username)
            form_data.append('password',this.password)
            axios.post('http://127.0.0.1:8000/login/',form_data).then(res=>{
                console.log(res.data)
                if(res.data.code == 200){
                    sessionStorage.setItem('admin',res.data.admin)
                    alert('登录成功')
                    this.$router.push({
                        path:'/index',
                        query:{'user_id':res.data.user_id}
                        })
                }else{
                alert('登录失败')
                }
            })
        }
    },
    created() {

    }
}
</script>

<style scoped>

</style>
